package familytree.yu.com.sso.config.jwt;

import familytree.yu.com.sso.constants.Constants;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @Author: yuyunbo
 * @Date: 2021/2/22 21:23
 * @Description:
 */
@Configuration
public class JwtConfig {

    /**
     * 生成具有jwt的token
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        //设置JWT使用签名
        accessTokenConverter.setSigningKey(Constants.SIGNINGKEY);
        return accessTokenConverter;
    }


    /**
     * token存储在jwt中
     */
    @Bean
    public JwtTokenStore jwtTokenStore(@Qualifier("jwtAccessTokenConverter") JwtAccessTokenConverter jwtAccessTokenConverter) {
        return new JwtTokenStore(jwtAccessTokenConverter);
    }

    /**
     * 存储了扩展的JWT信息
     *
     * @return
     */
    @Bean
    public Oauth2JwtTokenEnhancer oauth2JwtTokenEnhancer() {
        return new Oauth2JwtTokenEnhancer();
    }
}
